class Solution {
  public:
    int StrToInt(string str) {
        long long ret = 0;
        int n = str.size();
        int flag = 1, i = 0;
        if (str[0] == '+')
            str[0] = '0';
        if (str[0] == '-') 
        {
            flag = -1;
            i = 1;
        }
        for (; i < n; ++i) 
        {
            if (str[i] < '0' || str[i] > '9') 
            {
                return 0;
            }
            ret *= 10;
            ret += str[i] - '0';
        }
        return flag * ret;
    }
};